<template>
  <div>
    <mt-header :title="name" fixed class="store">
      <mt-button slot="left" icon="back" @click="goback"></mt-button>
    </mt-header>
    <div class="header" v-for="(item, i) in xhy_store" :key="i">
      <img :src="item.pic_store" alt="" />
      <div class="header-right">
        <span>起送￥{{ item.minPrice_store }}</span>
        <span>{{ item.range_store }}m</span>
        <span>{{ item.time_store }}分钟</span>
      </div>
      <div class="shoucang">
        <img :src="require(`../assets/img/shoucang_${n}.png`)" alt="" @click="shoucang">
        <p>收藏</p>
      </div>
      <h4>{{ item.way_store }}</h4>
    </div>
    <div class="container">
      <mt-navbar v-model="selected">
        <mt-tab-item id="1">商品</mt-tab-item>
        <mt-tab-item id="2">评价</mt-tab-item>
        <mt-tab-item id="3">商家</mt-tab-item>
      </mt-navbar>
    </div>
    <div class="main">
      <div class="left">
        <img src="../assets/img/sousuo.png" alt="">
        <ul>
          <li v-for="(item, i) in store_shop" :key="i">{{ item.name_shop }}</li>
        </ul>
      </div>
      <div class="right">
        <div class="clearfix" v-for="(item, i) in store_shop" :key="i">
          <img :src="item.pic_shop" alt="" />
          <div class="main-right clearfix">
            <h3>{{ item.name_shop }}</h3>
            <span>已售:{{ item.sale_shop }}</span>
            <span>赞:{{ item.like_shop }}</span>
            <p>￥{{ item.price_shop }}</p>
            <div class="btn">
              <button @click="add(i,item.price_shop)">+</button>
              <span :id="i">0</span>
              <button @click="reduce(i,item.price_shop)">-</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="footer-left">
        <img src="../assets/img/cart.png" alt="" />
        <button v-show="show">{{sum}}</button>
        <span v-show="no_show">购物车空空如也~</span>
        <span v-show="show">总价：{{all_price}}</span>
      </div>
      <div class="footer-right" id="pay">
        <span>{{pay}}</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.clearfix:after {
  content: "";
  display: block;
  clear: both;
}
.store {
  background-color: #cd5c5c;
}
.header {
  width: 100%;
  height: 100px;
  background-color: rgb(88, 94, 100);
  position: fixed;
  top: 40px;
}
.header > img {
  width: 80px;
  height: 80px;
  border-radius: 5px;
  margin: 5px;
  float: left;
}
.header h4 {
  color: #fff;
  margin-top: 10px;
}
.header-right {
  margin-top: 10px;
}
.header-right span {
  color: #fff;
  margin-right: 10px;
  border-right: 1px solid #fff;
  padding-right: 3px;
}
.header-right span:last-child{
  border: none;
}
.shoucang{
  float: right;
  margin: -20px 10px;
}
.shoucang p{
  color: #fff;
  padding-top: 0px;
}
.container {
  width: 100%;
  height: 30px;
  position: fixed;
  top: 140px;
}
.main {
  margin-top: 190px;
}
.left {
  width: 55px;
  height: 600px;
  background-color: #eee;
  position: fixed;
  overflow: scroll;
}
.left img{
  padding:10% 20%;
  border-bottom: 1px solid #333;
  margin-bottom: 20px;
}
.left::-webkit-scrollbar {
  display: none;
}
.left > ul > li {
  margin-bottom: 20px;
}
.right {
  margin-left: 55px;
}
.main .right img {
  width: 100px;
  height: 100px;
  float: left;
  margin: 10px;
  border-radius: 10px;
}
.main-right {
  border-bottom: 1px solid #eee;
}
.main-right h3 {
  padding-top: 10px;
}
.main-right span {
  color: rgb(56, 54, 54);
  line-height: 50px;
  padding-right: 10px;
}
.main-right p {
  color: #cd5c5c;
}
.main-right .btn{
  float: right;
  margin-top: -30px;
  margin-right: 5px;
}
.main-right .btn button{
  background-color: orangered;
  width: 25px;

}
.main-right .btn button:nth-child(3){
  display: none;
}
.main-right .btn span{
  padding-right: 0;
  font-size: 12px;
  display: none;
}
.footer {
  height: 60px;
  position: fixed;
  bottom: 0;
  left: 20px;
  right: 20px;
  border-radius: 30px;
}
.footer .footer-left {
  width: 70%;
  height: 100%;
  background-color: rgb(88, 94, 100);
  border-radius: 30px 0 0 30px;
}
.footer img {
  width: 50px;
  height: 50px;
  margin-left: 20px;
  margin-top: -50px;
  background-color: rgb(65, 62, 62);
  border-radius: 50%;
}
.footer button {
  background-color: red;
  position: absolute;
  top: -15px;
  left: 55px;
  border-radius: 50%;
  font-size: 12px;
}
.footer span {
  line-height: 60px;
  color: #fff;
  margin-left: 10px;
}
.footer .footer-right {
  width: 30%;
  height: 60px;
  background-color: rgb(99, 103, 107);
  position: absolute;
  top: 0;
  right: 0;
  border-radius: 0 30px 30px 0;
  padding-left: 10px;
}
</style>

<script>
export default {
  data() {
    return {
      selected: "1",
      store_shop: [],
      xhy_store: [],
      name:"",
      n:0,
      // 购物车
      sum:0,
      show:false,
      all_price:0,
      pay:"免费配送",
      no_show:true
    
    };
  },
  mounted() {
    // 接受数据
    let name = this.$route.query.name_store;
    // 商品数据
    this.axios.get(`/store/shop/${name}`).then((result) => {
      this.store_shop = result.data;
    });
    // 商家数据
    this.axios.get(`/store/store/${name}`).then((result) => {
      this.xhy_store = result.data;
      this.name = name;
    });
  },
  methods: {
    // 返回上一页
    goback() {
      this.$router.back();
    },
    
    add(e,price){
      let span=document.getElementById(e);
      // console.log(span);
      span.style.display='inline-block';
      span.innerHTML++;
      let btn=span.parentNode.lastChild;
      btn.style.display='inline-block';
      this.show=true;
      this.sum++;
      this.all_price=this.all_price+parseInt(`${price}`)
      this.pay="去结算";
      this.no_show=false;
      document.getElementById('pay').style.background='orangered'

    },
    reduce(e,price){
      let span=document.getElementById(e);
      if(span.innerHTML>1){
        span.innerHTML--;
      }else{
        span.style.display="none";
        let btn=span.parentNode.lastChild;
        btn.style.display="none";
      }
      if(this.sum>1){
        this.sum--;
      }else{
        this.show=false;
        this.pay="免费配送";
        this.no_show=true;
        document.getElementById('pay').style.background='rgb(99, 103, 107)';
      }
      this.all_price=this.all_price-parseInt(`${price}`)
    },
    shoucang(){
      this.n==0?this.n=1:this.n=0;
    }
  }
 
};
</script>